﻿<!DOCTYPE html>
<html>
<head>
<!--
  Copyright (c) 2015-2019 Jean-Marc VIGLINO, 
  released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
  <title>ol-ext: Swipe control</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="description" content="ol.control.Permalink add a premalink control to the map." />
  <meta name="keywords" content="ol3, control, swipe, compare" />

  <link rel="stylesheet" href="../style.css" />

  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>

  <!-- Openlayers -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></script>
  
  <!-- ol-ext -->
  <link rel="stylesheet" href="../../dist/ol-ext.css" />
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>
  <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
  <script src="https://unpkg.com/elm-pep"></script>

</head>
<body >
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>

  <a href="../../index.html">
    <h1>ol-ext: Swipe control</h1>
  </a>
  <div class="info">
    <i>ol.control.Swipe</i> is a control that add a split screen to compare two map overlays.
    <br/>
    Layers can be added to left (top) or right (bottom) side of the map.
    Layers that are not added are displayed on both sides.
  </div>

  <!-- Map div -->
  <div id="map" style="width:600px; height:400px;"></div>

  <div class="options" >
    <ul><li>
      <input id="ori" type="checkbox" onchange="ctrl.set('orientation',$(this).prop('checked')?'horizontal':'vertical')" /><label for="ori"> horizontal swipe</label>
    </li><li>
      <button type="button" onclick="ctrl.set('position', 0.5);">Reset position</button>
    </li></ul>
  </div>

  <script type="text/javascript">
    // Layers
    var osm = new ol.layer.Tile({
      source: new ol.source.OSM() 
    });
    var layer = new ol.layer.Geoportail('GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2');
    var label = new ol.layer.Geoportail('GEOGRAPHICALNAMES.NAMES');
    // GeoJSON layer
    var vectorSource = new ol.source.Vector({
      url: '../data/fond_guerre.geojson',
      projection: 'EPSG:3857',
      format: new ol.format.GeoJSON(),
      attributions: [ "&copy; <a href='https://data.culture.gouv.fr/explore/dataset/fonds-de-la-guerre-14-18-extrait-de-la-base-memoire'>data.culture.gouv.fr</a>" ],
      logo:"https://www.data.gouv.fr/s/avatars/37/e56718abd4465985ddde68b33be1ef.jpg" 
    });
    var vectorLayer = new ol.layer.VectorImage({ 
      source: vectorSource,
      style: new ol.style.Style({
        image: new ol.style.Icon({ src:"../data/camera.png", scale: 2 })
      })
    })

    // The map
    var map = new ol.Map({
      target: 'map',
      view: new ol.View({
        zoom: 12,
        center: [270701, 6247637]
      }),
      layers: [ layer, osm, label, vectorLayer ]
    });

    // Control
    var ctrl = new ol.control.Swipe();
    map.addControl(ctrl);
    // Set layer on left
    ctrl.addLayer(layer);
    // OSM on right
    ctrl.addLayer(osm, true);
    ctrl.addLayer(vectorLayer, true);

    /* WebGLTile * /
    var cog = new ol.source.GeoTIFF({
      sources: [
        { url: 'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/2020/S2A_36QWD_20200701_0_L2A/TCI.tif' }
      ]
    });
    var gl = new ol.layer.WebGLTile({
      // className: 'gl',
      source: cog 
    });
    map.addLayer(gl);
    map.setView(cog.getView());
    ctrl.addLayer(gl, false);
    /**/


  </script>

</body>
</html>
